aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/items/[id]/+page.server.ts
blob: d160c051e6d2de47459056a6822655720168df97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fd, auth, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";

export const load = async ({ params: { id } }) => {
  const item = await get(`/items/${id}`);
  return { item };
};

export const actions = {
  default: async ({ cookies, request, url }) => {
    const form = await fd(request);
    try {
      await post("/items", form, auth(cookies));
    } catch (e: any) {
      return fail(400, { message: e.message });
    }

    const success = `/${url.pathname.split("/")[1]}`;
    redirect(307, success);
  },
};